{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最值归一化（Normalization）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "x = np.random.randint(0, 100, size=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.52525253, 0.13131313, 0.26262626, 0.60606061, 0.03030303,\n",
       "       0.1010101 , 0.52525253, 0.21212121, 0.47474747, 0.70707071,\n",
       "       0.76767677, 0.62626263, 0.96969697, 0.2020202 , 0.58585859,\n",
       "       0.93939394, 0.84848485, 0.73737374, 0.68686869, 0.36363636,\n",
       "       0.28282828, 0.06060606, 0.87878788, 0.26262626, 0.19191919,\n",
       "       0.77777778, 0.35353535, 0.        , 0.8989899 , 0.56565657,\n",
       "       0.06060606, 0.57575758, 0.34343434, 0.51515152, 0.92929293,\n",
       "       0.11111111, 0.96969697, 0.6969697 , 0.91919192, 0.67676768,\n",
       "       0.66666667, 0.62626263, 0.32323232, 0.6969697 , 0.24242424,\n",
       "       0.91919192, 0.13131313, 0.16161616, 0.46464646, 0.75757576,\n",
       "       0.90909091, 0.        , 0.04040404, 0.34343434, 0.09090909,\n",
       "       0.96969697, 0.36363636, 0.27272727, 0.06060606, 0.60606061,\n",
       "       0.58585859, 0.53535354, 0.06060606, 0.01010101, 0.41414141,\n",
       "       0.3030303 , 0.50505051, 0.27272727, 0.1010101 , 0.73737374,\n",
       "       0.53535354, 0.87878788, 0.67676768, 0.08080808, 0.31313131,\n",
       "       0.01010101, 0.21212121, 1.        , 0.13131313, 0.17171717,\n",
       "       0.22222222, 0.82828283, 0.62626263, 0.45454545, 0.94949495,\n",
       "       0.58585859, 0.29292929, 0.47474747, 0.52525253, 0.11111111,\n",
       "       0.74747475, 0.73737374, 0.85858586, 0.56565657, 0.78787879,\n",
       "       0.45454545, 0.68686869, 0.03030303, 0.08080808, 0.96969697])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x - np.min(x)) / (np.max(x) - np.min(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[69, 16],\n",
       "       [ 3, 29],\n",
       "       [90, 64],\n",
       "       [23, 31],\n",
       "       [83, 14],\n",
       "       [40, 12],\n",
       "       [61, 70],\n",
       "       [46,  6],\n",
       "       [30, 38],\n",
       "       [21, 80]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.random.randint(0, 100, (50, 2))\n",
    "x[:10, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[69., 16.],\n",
       "       [ 3., 29.],\n",
       "       [90., 64.],\n",
       "       [23., 31.],\n",
       "       [83., 14.],\n",
       "       [40., 12.],\n",
       "       [61., 70.],\n",
       "       [46.,  6.],\n",
       "       [30., 38.],\n",
       "       [21., 80.]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array(x, dtype=float)   # 最值归一化计算需要转为浮点型\n",
    "x[:10, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.69473684, 0.16161616],\n",
       "       [0.        , 0.29292929],\n",
       "       [0.91578947, 0.64646465],\n",
       "       [0.21052632, 0.31313131],\n",
       "       [0.84210526, 0.14141414],\n",
       "       [0.38947368, 0.12121212],\n",
       "       [0.61052632, 0.70707071],\n",
       "       [0.45263158, 0.06060606],\n",
       "       [0.28421053, 0.38383838],\n",
       "       [0.18947368, 0.80808081],\n",
       "       [0.24210526, 0.06060606],\n",
       "       [0.64210526, 0.7979798 ],\n",
       "       [0.72631579, 0.77777778],\n",
       "       [0.01052632, 0.62626263],\n",
       "       [0.85263158, 0.12121212],\n",
       "       [0.69473684, 0.71717172],\n",
       "       [0.11578947, 0.2020202 ],\n",
       "       [0.13684211, 0.04040404],\n",
       "       [0.33684211, 0.39393939],\n",
       "       [0.58947368, 0.84848485],\n",
       "       [0.90526316, 0.77777778],\n",
       "       [0.41052632, 0.60606061],\n",
       "       [0.15789474, 0.57575758],\n",
       "       [0.71578947, 0.14141414],\n",
       "       [0.16842105, 0.90909091],\n",
       "       [0.23157895, 0.13131313],\n",
       "       [0.96842105, 0.16161616],\n",
       "       [0.10526316, 0.50505051],\n",
       "       [0.11578947, 0.24242424],\n",
       "       [0.67368421, 0.56565657],\n",
       "       [0.50526316, 0.7979798 ],\n",
       "       [0.42105263, 0.09090909],\n",
       "       [0.73684211, 0.03030303],\n",
       "       [0.91578947, 0.98989899],\n",
       "       [0.94736842, 0.61616162],\n",
       "       [0.17894737, 0.22222222],\n",
       "       [0.72631579, 0.63636364],\n",
       "       [0.83157895, 0.54545455],\n",
       "       [0.75789474, 0.62626263],\n",
       "       [1.        , 0.37373737],\n",
       "       [0.56842105, 1.        ],\n",
       "       [1.        , 0.24242424],\n",
       "       [0.98947368, 0.46464646],\n",
       "       [0.75789474, 0.43434343],\n",
       "       [0.        , 0.        ],\n",
       "       [0.81052632, 0.32323232],\n",
       "       [0.90526316, 0.33333333],\n",
       "       [0.08421053, 0.65656566],\n",
       "       [0.02105263, 0.32323232],\n",
       "       [0.12631579, 0.32323232]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_min = np.min(x, axis=0)\n",
    "x_max = np.max(x, axis=0)\n",
    "(x - x_min) / (x_max - x_min)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x23627f6d7b8>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAVG0lEQVR4nO3df4xlZXnA8e9TfuiiNQMykP3BdteUrBqJLpkYdI2xoAHUyIZggpq6MTT7R21Ea9DF/tMmTVij8VdiaLagrk0jWiQLESMluxhbU6mzrhF0oVCssMPKrtFVYzYF9Okf92yZXe78ur/OOe/5fpLJzD33ztz3zLn3ue/7nPd9TmQmkqSy/FHdDZAkjZ7BXZIKZHCXpAIZ3CWpQAZ3SSrQ6XU3AODcc8/NDRs21N0MSWqV/fv3/yIzp/vd14jgvmHDBmZnZ+tuhiS1SkT8bKH7TMtIUoEM7pJUIIO7JBVoyeAeEV+IiCMR8eC8bedExL0R8Uj1/exqe0TE5yLi0Yj4UURcPM7GS5L6W07P/UvAFads2wHszcwLgb3VbYArgQurr+3AzaNppiRpJZacLZOZ34mIDadsvgp4U/XzbuDbwEer7V/OXjWy70XEVESszszDo2qw1FZ7DszxiXse5sljx1kztYobLt/E1s1r626WCjVozv38EwG7+n5etX0t8MS8xx2qtj1PRGyPiNmImD169OiAzZDaYc+BOW684wHmjh0ngbljx7nxjgfYc2Cu7qapUKM+oRp9tvWtKZyZuzJzJjNnpqf7zsGXivGJex7m+DO/P2nb8Wd+zyfuebimFmkhew7MsWXnPjbuuJstO/e19gN40EVMT51It0TEauBItf0QcMG8x60DnhymgVIJnjx2fEXbVY8TI6wTH8QnRlhA61Jog/bc7wK2VT9vA+6ct/291ayZS4Bfm2+XYM3UqhVtVz1KGmEtZyrkV4D/ADZFxKGIuA7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"<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(x[:,0], x[:, 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(51.78, 43.3)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(x[:, 0]), np.mean(x[:, 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(31.152072162217394, 27.725259241348855)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(x[:, 0]), np.std(x[:,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 均值方差归一化（Standardization）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2 = np.random.randint(0, 100,(50, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2 = np.array(x2, dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.24121618,  0.12010318],\n",
       "       [ 0.96986973, -0.22903397],\n",
       "       [-0.9295554 , -0.85748085],\n",
       "       [ 1.59009018,  1.69122038],\n",
       "       [-0.46439006,  0.50415405],\n",
       "       [ 0.8535784 , -1.17170429],\n",
       "       [-0.50315384,  1.44682437],\n",
       "       [-0.11551606, -1.59066887],\n",
       "       [ 0.81481462,  1.30716951],\n",
       "       [-1.16213807, -1.45101401],\n",
       "       [-0.69697273, -0.7527397 ],\n",
       "       [-0.19304362,  0.43432662],\n",
       "       [ 1.86143663,  1.20242836],\n",
       "       [-1.23966563, -0.85748085],\n",
       "       [ 0.77605084, -0.61308484],\n",
       "       [ 0.07830283, -1.48592773],\n",
       "       [-0.0379885 , -1.20661801],\n",
       "       [ 1.55132641,  1.34208322],\n",
       "       [-0.65820895, -0.57817113],\n",
       "       [-1.85988608, -0.43851627],\n",
       "       [-1.23966563,  1.62139294],\n",
       "       [ 0.15583039, -0.57817113],\n",
       "       [-0.0379885 , -1.06696314],\n",
       "       [ 0.96986973, -0.64799856],\n",
       "       [-1.58853963, -0.99713571],\n",
       "       [ 0.03953905,  0.67872263],\n",
       "       [ 0.54346817,  0.32958547],\n",
       "       [-0.07675228,  1.69122038],\n",
       "       [-0.89079162,  1.23734207],\n",
       "       [ 0.23335795,  0.32958547],\n",
       "       [ 0.38841306, -0.47342998],\n",
       "       [ 1.51256263,  1.13260093],\n",
       "       [-0.69697273,  0.64380891],\n",
       "       [ 0.46594061, -0.08937911],\n",
       "       [-1.16213807, -1.52084144],\n",
       "       [ 0.77605084,  1.62139294],\n",
       "       [-0.77450029,  1.23734207],\n",
       "       [ 1.7451453 ,  0.08518947],\n",
       "       [ 0.50470439, -1.17170429],\n",
       "       [-1.4722483 , -0.01955168],\n",
       "       [-1.43348452, -1.10187686],\n",
       "       [ 1.62885396,  0.64380891],\n",
       "       [-0.81326407, -0.82256714],\n",
       "       [ 1.62885396,  0.53906777],\n",
       "       [-0.0379885 ,  0.12010318],\n",
       "       [-0.19304362, -0.71782599],\n",
       "       [-0.11551606,  0.8532912 ],\n",
       "       [-1.58853963, -1.45101401],\n",
       "       [-0.65820895,  0.71363634],\n",
       "       [ 0.3108855 ,  0.36449919]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x2_mean = np.mean(x2, axis=0)\n",
    "x2_std = np.std(x2, axis=0)\n",
    "(x2 - x2_mean) / x2_std"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x23623394240>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAD4CAYAAAAEhuazAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAXhElEQVR4nO3df4xlZX3H8ffH5YcTaxxglx87gCwtXX90WxcnRN2mQQUXqWHXRSL2D6HVbGxL2qYJ6RISbUiaXUrSpBZasyIREgO2CMta1iK4GPojKLMusPyUFTHMLJERuihxq4Lf/nHPMHcv9965M/fcc55zzueVTPb+ONzny7lnvvOc5/me5ygiMDOzZnlD2QGYmVnxnPzNzBrIyd/MrIGc/M3MGsjJ38ysgY4oO4B+li9fHqeddlrZYZiZVcaePXt+EhErFtou6eR/2mmnMTU1VXYYZmaVIelHg2znYR8zswZy8jczayAnfzOzBnLyNzNrICd/M7MGcvI3M2ugpEs9zcqyY+8M19z1JAcOHmLl+BiXr1/NxrUTZYdlCajLseHkb9Zhx94ZrrhtH4d+9SoAMwcPccVt+wAq+Utu+anTseFhH7MO19z15Gu/3HMO/epVrrnryZIislTU6dhw8jfrcODgoUW9bs1Rp2PDwz4Jq8vYYtWsHB9jpssv88rxsRKiSYePx3odG+75J2pubHHm4CGC+bHFHXtnyg6t9i5fv5qxI5cd9trYkcu4fP3qkiIqn4/HljodG07+iarT2GLVbFw7wdZNa5gYH0PAxPgYWzetaVwvt52Px5Y6HRse9klUncYWq2jj2olK/kKPio/HeXU5NtzzT1SvMcQqji1a9fl4rB8n/0TVaWzRqs/HY/142CdRc6eVTa+usDT4eKwfRcTwHyLdAHwEeD4ifqfL+2cDdwA/zF66LSKuWuhzJycnw3fyMjMbnKQ9ETG50HZ59fy/DFwL3NRnm/+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kg6Hrhb0hNZjyOF+Erdh4v4mFOzfXg6sFvSvoj4QT4RdjXIfhn5vutjkLa/DtwcEb+Q9BlaZykfGHlkgytz/w3qe7TWy3lZ0vnADuCMMgKR9BvA14C/ioifdr7d5T/puS9LT/4RcU6/9yVdAnwE+GBkA1sdpoH23szJwIH8Ilw4xgE/40D27/OSbqd1yp5L8s8hvlL3oaQfSzopIp7LTlOf7/EZc/vwaUnfptX7GWXyH2S/zG0zLekI4C0UN4SwYHwR8ULb0y/SmjtLyciPvWG1J9mI2CXpnyUtj4hCF3yTdCStxP+ViLityyaL2pdJD/tIOg/4G+CCiPh5j80eAM6QtErSUbQm3QqpBBmUpDdJevPcY1oT2V0rC0pS9j7cCVySPb4EeN3ZiqRjJB2dPV4OrAMeG3Fcg+yX9tg/Buzu0UkpJb6OMd8LaI0Vp2Qn8MmsUuU9wEtzQ4CpkHTi3DyOpLNo5c0X+v9Xuccg4EvA4xHxDz02W9y+LHMGe4AZ7v20xrAezH7mqipWArs6Zrm/T6sXeGXBMX6U1l/cXwA/Bu7qjJFWNcZD2c+jRcY4SHwJ7MPjgG8BT2X/Hpu9Pglcnz1+H7Av24f7gE8VFNvr9gtwFa0OCcAbgX/LjtXvAqcXvO8Wim9rdsw9BNwLvK3g+G4GngN+lR2HnwI+A3wme1/AdVn8++hTMVdijJe17cP7gfeVEOPv0xrCebgtH54/zL708g5mZg2U9LCPmZmNhpO/mVkDOfmbmTWQk7+ZWQM5+ZuZNZCTv5lZAzn5m5k10P8D0fxDxsufI2oAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x2[:, 0], x2[:, 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.17683641e-16, -1.02140518e-16])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(x2, axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### scikit-learn中的StandardScaler归一化测试数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets\n",
    "\n",
    "iris = datasets.load_iris()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = iris.data\n",
    "y = iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5.1, 3.5, 1.4, 0.2],\n",
       "       [4.9, 3. , 1.4, 0.2],\n",
       "       [4.7, 3.2, 1.3, 0.2],\n",
       "       [4.6, 3.1, 1.5, 0.2],\n",
       "       [5. , 3.6, 1.4, 0.2],\n",
       "       [5.4, 3.9, 1.7, 0.4],\n",
       "       [4.6, 3.4, 1.4, 0.3],\n",
       "       [5. , 3.4, 1.5, 0.2],\n",
       "       [4.4, 2.9, 1.4, 0.2],\n",
       "       [4.9, 3.1, 1.5, 0.1]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[:10, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "standardScaler = StandardScaler()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "StandardScaler(copy=True, with_mean=True, with_std=True)"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "standardScaler.fit(x_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5.83416667, 3.08666667, 3.70833333, 1.17      ])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "standardScaler.mean_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.81019502, 0.44327067, 1.76401924, 0.75317107])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "standardScaler.scale_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.90616043,  0.93246262, -1.30856471, -1.28788802],\n",
       "       [-1.15301457, -0.19551636, -1.30856471, -1.28788802],\n",
       "       [-0.16559799, -0.64670795,  0.22203084,  0.17260355],\n",
       "       [ 0.45153738,  0.70686683,  0.95898425,  1.50032315],\n",
       "       [-0.90616043, -1.32349533, -0.40154513, -0.09294037],\n",
       "       [ 1.43895396,  0.25567524,  0.56216318,  0.30537551],\n",
       "       [ 0.3281103 , -1.09789954,  1.0723617 ,  0.30537551],\n",
       "       [ 2.1795164 , -0.19551636,  1.63924894,  1.23477923],\n",
       "       [-0.78273335,  2.2860374 , -1.25187599, -1.42065998],\n",
       "       [ 0.45153738, -2.00028272,  0.44878573,  0.43814747],\n",
       "       [ 1.80923518, -0.42111215,  1.46918276,  0.83646335],\n",
       "       [ 0.69839152,  0.25567524,  0.90229552,  1.50032315],\n",
       "       [ 0.20468323,  0.70686683,  0.44878573,  0.57091943],\n",
       "       [-0.78273335, -0.87230374,  0.10865339,  0.30537551],\n",
       "       [-0.53587921,  1.38365421, -1.25187599, -1.28788802],\n",
       "       [-0.65930628,  1.38365421, -1.25187599, -1.28788802],\n",
       "       [-1.0295875 ,  0.93246262, -1.19518726, -0.75680017],\n",
       "       [-1.77014994, -0.42111215, -1.30856471, -1.28788802],\n",
       "       [-0.04217092, -0.87230374,  0.10865339,  0.03983159],\n",
       "       [-0.78273335,  0.70686683, -1.30856471, -1.28788802],\n",
       "       [-1.52329579,  0.70686683, -1.30856471, -1.15511606],\n",
       "       [ 0.82181859,  0.25567524,  0.78891808,  1.10200727],\n",
       "       [-0.16559799, -0.42111215,  0.27871956,  0.17260355],\n",
       "       [ 0.94524567, -0.19551636,  0.39209701,  0.30537551],\n",
       "       [ 0.20468323, -0.42111215,  0.44878573,  0.43814747],\n",
       "       [-1.39986872,  0.25567524, -1.19518726, -1.28788802],\n",
       "       [-1.15301457,  1.15805842, -1.30856471, -1.42065998],\n",
       "       [ 1.06867274,  0.03007944,  1.0723617 ,  1.63309511],\n",
       "       [ 0.57496445, -0.87230374,  0.67554063,  0.83646335],\n",
       "       [ 0.3281103 , -0.64670795,  0.56216318,  0.03983159],\n",
       "       [ 0.45153738, -0.64670795,  0.6188519 ,  0.83646335],\n",
       "       [-0.16559799,  2.96282478, -1.25187599, -1.0223441 ],\n",
       "       [ 0.57496445, -1.32349533,  0.67554063,  0.43814747],\n",
       "       [ 0.69839152, -0.42111215,  0.33540828,  0.17260355],\n",
       "       [-0.90616043,  1.60925001, -1.02512109, -1.0223441 ],\n",
       "       [ 1.19209981, -0.64670795,  0.6188519 ,  0.30537551],\n",
       "       [-0.90616043,  0.93246262, -1.30856471, -1.15511606],\n",
       "       [-1.89357701, -0.19551636, -1.47863088, -1.42065998],\n",
       "       [ 0.08125616, -0.19551636,  0.78891808,  0.83646335],\n",
       "       [ 0.69839152, -0.64670795,  1.0723617 ,  1.23477923],\n",
       "       [-0.28902506, -0.64670795,  0.67554063,  1.10200727],\n",
       "       [-0.41245214, -1.54909113, -0.00472406, -0.22571233],\n",
       "       [ 1.31552689,  0.03007944,  0.67554063,  0.43814747],\n",
       "       [ 0.57496445,  0.70686683,  1.0723617 ,  1.63309511],\n",
       "       [ 0.82181859, -0.19551636,  1.18573914,  1.36755119],\n",
       "       [-0.16559799,  1.60925001, -1.13849854, -1.15511606],\n",
       "       [ 0.94524567, -0.42111215,  0.50547446,  0.17260355],\n",
       "       [ 1.06867274,  0.48127103,  1.12905042,  1.76586707],\n",
       "       [-1.27644165, -0.19551636, -1.30856471, -1.42065998],\n",
       "       [-1.0295875 ,  1.15805842, -1.30856471, -1.28788802],\n",
       "       [ 0.20468323, -0.19551636,  0.6188519 ,  0.83646335],\n",
       "       [-1.0295875 , -0.19551636, -1.19518726, -1.28788802],\n",
       "       [ 0.3281103 , -0.19551636,  0.67554063,  0.83646335],\n",
       "       [ 0.69839152,  0.03007944,  1.01567297,  0.83646335],\n",
       "       [-0.90616043,  1.38365421, -1.25187599, -1.0223441 ],\n",
       "       [-0.16559799, -0.19551636,  0.27871956,  0.03983159],\n",
       "       [-1.0295875 ,  0.93246262, -1.36525344, -1.15511606],\n",
       "       [-0.90616043,  1.60925001, -1.25187599, -1.15511606],\n",
       "       [-1.52329579,  0.25567524, -1.30856471, -1.28788802],\n",
       "       [-0.53587921, -0.19551636,  0.44878573,  0.43814747],\n",
       "       [ 0.82181859, -0.64670795,  0.50547446,  0.43814747],\n",
       "       [ 0.3281103 , -0.64670795,  0.16534211,  0.17260355],\n",
       "       [-1.27644165,  0.70686683, -1.19518726, -1.28788802],\n",
       "       [-0.90616043,  0.48127103, -1.13849854, -0.88957213],\n",
       "       [-0.04217092, -0.87230374,  0.78891808,  0.96923531],\n",
       "       [-0.28902506, -0.19551636,  0.22203084,  0.17260355],\n",
       "       [ 0.57496445, -0.64670795,  0.78891808,  0.43814747],\n",
       "       [ 1.06867274,  0.48127103,  1.12905042,  1.23477923],\n",
       "       [ 1.68580811, -0.19551636,  1.18573914,  0.57091943],\n",
       "       [ 1.06867274, -0.19551636,  0.8456068 ,  1.50032315],\n",
       "       [-1.15301457,  0.03007944, -1.25187599, -1.42065998],\n",
       "       [-1.15301457, -1.32349533,  0.44878573,  0.70369139],\n",
       "       [-0.16559799, -1.32349533,  0.73222935,  1.10200727],\n",
       "       [-1.15301457, -1.54909113, -0.23147896, -0.22571233],\n",
       "       [-0.41245214, -1.54909113,  0.05196466, -0.09294037],\n",
       "       [ 1.06867274, -1.32349533,  1.18573914,  0.83646335],\n",
       "       [ 0.82181859, -0.19551636,  1.01567297,  0.83646335],\n",
       "       [-0.16559799, -1.09789954, -0.11810151, -0.22571233],\n",
       "       [ 0.20468323, -2.00028272,  0.73222935,  0.43814747],\n",
       "       [ 1.06867274,  0.03007944,  0.56216318,  0.43814747],\n",
       "       [-1.15301457,  0.03007944, -1.25187599, -1.28788802],\n",
       "       [ 0.57496445, -1.32349533,  0.73222935,  0.96923531],\n",
       "       [-1.39986872,  0.25567524, -1.36525344, -1.28788802],\n",
       "       [ 0.20468323, -0.87230374,  0.78891808,  0.57091943],\n",
       "       [-0.04217092, -1.09789954,  0.16534211,  0.03983159],\n",
       "       [ 1.31552689,  0.25567524,  1.12905042,  1.50032315],\n",
       "       [-1.77014994, -0.19551636, -1.36525344, -1.28788802],\n",
       "       [ 1.56238103, -0.19551636,  1.24242787,  1.23477923],\n",
       "       [ 1.19209981,  0.25567524,  1.24242787,  1.50032315],\n",
       "       [-0.78273335,  0.93246262, -1.25187599, -1.28788802],\n",
       "       [ 2.54979762,  1.60925001,  1.52587149,  1.10200727],\n",
       "       [ 0.69839152, -0.64670795,  1.0723617 ,  1.36755119],\n",
       "       [-0.28902506, -0.42111215, -0.06141278,  0.17260355],\n",
       "       [-0.41245214,  2.51163319, -1.30856471, -1.28788802],\n",
       "       [-1.27644165, -0.19551636, -1.30856471, -1.15511606],\n",
       "       [ 0.57496445, -0.42111215,  1.0723617 ,  0.83646335],\n",
       "       [-1.77014994,  0.25567524, -1.36525344, -1.28788802],\n",
       "       [-0.53587921,  1.8348458 , -1.13849854, -1.0223441 ],\n",
       "       [-1.0295875 ,  0.70686683, -1.19518726, -1.0223441 ],\n",
       "       [ 1.06867274, -0.19551636,  0.73222935,  0.70369139],\n",
       "       [-0.53587921,  1.8348458 , -1.36525344, -1.0223441 ],\n",
       "       [ 2.30294347, -0.64670795,  1.69593766,  1.10200727],\n",
       "       [-0.28902506, -0.87230374,  0.27871956,  0.17260355],\n",
       "       [ 1.19209981, -0.19551636,  1.01567297,  1.23477923],\n",
       "       [-0.41245214,  0.93246262, -1.36525344, -1.28788802],\n",
       "       [-1.27644165,  0.70686683, -1.02512109, -1.28788802],\n",
       "       [-0.53587921,  0.70686683, -1.13849854, -1.28788802],\n",
       "       [ 2.30294347,  1.60925001,  1.69593766,  1.36755119],\n",
       "       [ 1.31552689,  0.03007944,  0.95898425,  1.23477923],\n",
       "       [-0.28902506, -1.32349533,  0.10865339, -0.09294037],\n",
       "       [-0.90616043,  0.70686683, -1.25187599, -1.28788802],\n",
       "       [-0.90616043,  1.60925001, -1.19518726, -1.28788802],\n",
       "       [ 0.3281103 , -0.42111215,  0.56216318,  0.30537551],\n",
       "       [-0.04217092,  2.0604416 , -1.42194216, -1.28788802],\n",
       "       [-1.0295875 , -2.45147431, -0.11810151, -0.22571233],\n",
       "       [ 0.69839152,  0.25567524,  0.44878573,  0.43814747],\n",
       "       [ 0.3281103 , -0.19551636,  0.50547446,  0.30537551],\n",
       "       [ 0.08125616,  0.25567524,  0.6188519 ,  0.83646335],\n",
       "       [ 0.20468323, -2.00028272,  0.16534211, -0.22571233],\n",
       "       [ 1.93266225, -0.64670795,  1.35580532,  0.96923531]])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train_standard = standardScaler.transform(x_train)\n",
    "x_train_standard"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_test_standard = standardScaler.transform(x_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 归一化数据集使用KNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "knn_clf = KNeighborsClassifier(n_neighbors=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
       "                     metric_params=None, n_jobs=None, n_neighbors=3, p=2,\n",
       "                     weights='uniform')"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn_clf.fit(x_train_standard, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn_clf.score(x_test_standard, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
